<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY copy "&#169;">
  <!ENTITY nbsp "&#160;">
  <!ENTITY laquo "&#171;">
  <!ENTITY raquo "&#187;">
]>
<xsl:stylesheet xmlns="http://www.w3.org/1999/xhtml"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

  <xsl:include href="layout.xsl"/>

  <xsl:template match="/">
    <xsl:apply-templates />
  </xsl:template>

  <xsl:template name="Head-List">
    <xsl:param name="ddMenu"/>
    <div class="contenthead">

      <xsl:call-template name="Create_Path">
        <xsl:with-param name="without_last" select="1"/>
      </xsl:call-template>
      <div class="top">
        <span class="title">
          <xsl:value-of select="$Cats/row[id=$Content/@cat]/title" />
        </span>
        <span class="actions">
          <xsl:choose>
            <xsl:when test="$Cat=61 or $Cat=485">
              <xsl:choose>
                <xsl:when test="$Settings/action='index'">
                  <!--<nav class="mainmenu">
                                <ul>
                                <li class="dropdown" onmouseover="$(this).find('nav').show(); $(this).addClass('hover');" onmouseout="$(this).find('nav').hide(); $(this).removeClass('hover');">
                                        <span>
                                        <xsl:text>Додати</xsl:text>
                                        </span>
                                    <nav class="submenu" style="display:none;">
                                    <ul>
                                        <xsl:for-each select="$Main/ddMenu/row">
                                        <li>
                                            <a href="/{$Controller}/add/{id}">
                                            <xsl:value-of select="name"/>
                                            </a>
                                        </li>
                                        </xsl:for-each>
                                    </ul>
                                    </nav>
                                </li>
                                </ul>
                            </nav>-->
                  <span>
                    <select name="idDdMenu" id="idDdMenu">
                      <xsl:if test="not($Main/ddMenu/row)">
                        <xsl:attribute name="disabled">disabled</xsl:attribute>
                      </xsl:if>
                      <option value="0">
                        Не задано
                      </option>
                      <xsl:for-each select="$Main/ddMenu/row">
                        <option value="{id}">
                          <xsl:value-of select="short_text" />
                        </option>
                      </xsl:for-each>
                    </select>
                    <input name="addById" id="addById" value="Додати" type="button"/>
                  </span>
                  <div class="cb_aside" id="cb_aside" title="Блок Фільтрації">
                    &lt;&lt;
                  </div>
                </xsl:when>
                <xsl:otherwise></xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:when test="$Cat = 344">
                <xsl:if test="$Settings/action='index'">
                    <div class="cb_aside" id="cb_aside" title="Блок Фільтрації">
                        &lt;&lt;
                    </div>
                </xsl:if>
            </xsl:when>
            <xsl:when test="$Cat=264">
              <xsl:choose>
                <xsl:when test="$Settings/action='index'">                  
                  <div class="cb_aside" id="cb_aside" title="Блок Фільтрації">
                    &gt;&gt;
                  </div>
                </xsl:when>
                <xsl:otherwise></xsl:otherwise>
              </xsl:choose>
            </xsl:when>
            <xsl:when test="$Cat = 124">
              <input name="button_add" value="Завантажити XML" type="button" onclick="$('div.upload-window').prsfileupload('open');"/>
            </xsl:when>
            <!-- Map View -->
            <xsl:when test="$Cat = 35">
            </xsl:when>
            <xsl:when test="$Cat = 63">
              <input type="text" id="get_serach_cadnum" value="{$Main/@cadnum}" placeholder="Введіть кадастровий номер" size="29"/>
              <input type="button" value="Шукати" id="btn_serach_cadnum"/>
            </xsl:when>
            <xsl:when test="$Cat = 385 or $Cat = 324">
              <input name="button_add" value="Завантажити" type="button" onclick="$('div.upload-window').rentappsupload('open');"/>
            </xsl:when>
            <xsl:when test="$Cat = 324 or $Cat = 325"></xsl:when>
            <xsl:when test="$Cat = 125">
              <input name="button_add" value="Завантажити IN4" type="button" onclick="$('div.upload-window').prsfileupload('open');"/>
            </xsl:when>
            <xsl:otherwise>
              <input name="button_add" id="button_add" value="Добавить" type="button" />
            </xsl:otherwise>
          </xsl:choose>
          <!--  <input name="button_remove" id="button_remove" value="- Удалить" type="button"/>-->
        </span>
      </div>
    </div>

    <xsl:choose>
        <xsl:when test="$Cat = 124">
            <div class="sort">
                <span>З виділеними:</span>
                <a href="javascript:;" id="exchange_files_button_remove">видалити</a>
            </div>
        </xsl:when>
        <xsl:when test="$Cat = 125">
            <div class="sort">
                <span>З виділеними:</span>
                <a href="javascript:;" id="exchange_files_button_remove">видалити</a>
            </div>
        </xsl:when>
    </xsl:choose>
    <!--
    <div class="sort">
      <span>С выделеными:</span>

          <a href="javascript:;" id="button_remove">удалить</a>
        </div>-->
    </xsl:template>

    <xsl:template match="List">
        <link rel="stylesheet" type="text/css" href="/css/ArtPager.css" />
        <script type="text/javascript" src="/js/list_actions.js"></script>
        <script type="text/javascript" src="/js/listing.js"></script>

        <form id="list_form" name="list_form" action="" method="post">
            <input type="hidden" id="controller" value="{$Controller}"/>
            <input type="hidden" id="table_name" value="{$Main/List/head/@table_name}"/>
            <input type="hidden" id="url_edit" value="">
                <xsl:choose>
                    <xsl:when test="$Main/List/params/link">
                        <xsl:attribute name="value">
                            <xsl:value-of select="$Main/List/params/link"/>
                        </xsl:attribute>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="value">
                            <xsl:text>/</xsl:text>
                            <xsl:value-of select="$Controller"/>
                            <xsl:text>/</xsl:text>
                        </xsl:attribute>
                    </xsl:otherwise>
                </xsl:choose>
            </input>
            <table width="100%" border="0" cellpadding="0" cellspacing="0" class="widefat"  ondblclick="clearSelection()">

                <thead>
                    <tr class="header" bgColor="#EFEFEF">
                        <!-- <td width="10" class="action">
                          <a href="?sort=norder&amp;dr=0">#</a>
                        </td>-->
                        <xsl:if test="$Main/List/params/checkboxes = 1">
                            <td width="5%" class="action" >
                                <input id="check_all" type="checkbox"/>
                            </td>
                        </xsl:if>

                        <xsl:for-each select="head/row">
                            <td>
                                <xsl:if test="@width">
                                    <xsl:attribute name="width">
                                        <xsl:value-of select="@width"/>
                                    </xsl:attribute>
                                </xsl:if>

                                <xsl:if test="sort_field_name = /page/content/Main/List/head/@sort">
                                    <xsl:if test="@sort = 1">
                                        <xsl:if test="/page/content/Main/List/head/@dr = 0">
                                            <img src="{$Images}/arrow_down.gif" width="14" height="6" />
                                        </xsl:if>
                                        <xsl:if test="/page/content/Main/List/head/@dr = 1">
                                            <img src="{$Images}/arrow_up.gif" width="14" height="6" />
                                        </xsl:if>
                                    </xsl:if>
                                </xsl:if>

                                <xsl:choose>
                                    <xsl:when test="@sort = 1">
                                        <xsl:choose>
                                            <xsl:when test="sort_field_name = /page/content/Main/List/head/@sort">
                                                <xsl:choose>
                                                    <xsl:when test="/page/content/Main/List/head/@dr = 0">
                                                        <A href="{$This}?sort={sort_field_name}&amp;dr=1">
                                                            <xsl:value-of select="title"/>
                                                        </A>
                                                    </xsl:when>
                                                    <xsl:otherwise>
                                                        <A href="{$This}?sort={sort_field_name}&amp;dr=0">
                                                            <xsl:value-of select="title"/>
                                                        </A>
                                                    </xsl:otherwise>
                                                </xsl:choose>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <A href="{$This}?sort={sort_field_name}&amp;dr=0">
                                                    <xsl:value-of select="title"/>
                                                </A>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="title"/>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </td>
                        </xsl:for-each>

                        <xsl:for-each select="$Main/List/func/row">
                            <td>
                                <xsl:choose>
                                    <xsl:when test="type = 'order'">
                                        <a href="/{$Controller}/reorder/id/{$Main/@id}">
                                            <xsl:value-of select="title"/>
                                        </a>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="title"/>
                                    </xsl:otherwise>
                                </xsl:choose>

                            </td>
                        </xsl:for-each>

                    </tr>
                </thead>
                <tbody>
                    <xsl:if test="count(data/data/row) = 0">
                        <tr>
                            <td colspan="{$Main/List/head/@count}" align="center" rel="0">
                                <xsl:if test="$Main/List/func/@count">
                                    <xsl:attribute name="colspan">
                                        <xsl:value-of select="$Main/List/head/@count + $Main/List/func/@count"/>
                                    </xsl:attribute>
                                </xsl:if>
                                Записей нет
                            </td>
                        </tr>
                    </xsl:if>

                    <xsl:for-each select="data/data/row">
                        <xsl:variable name="id" select="id" />
                        <xsl:variable name="file_name" select="file_name" />
                        <xsl:variable name="path" select="path" />

                        <tr class="data-row" rel="{id}">
                            <!--<td>
                              <xsl:value-of select="position()"/>
                            </td>
                            -->
                            <xsl:if test="$Main/List/params/checkboxes = 1">
                                <td>
                                    <input type="checkbox" value="{$id}" name="selected_id[]" class="checkboxlist"/>
                                </td>
                            </xsl:if>

                            <!-- Data List -->
                            <xsl:for-each select="node()[@type = 'field']">
                                <xsl:choose>
                                    <!-- AVATAR -->
                                    <xsl:when test="name(.)='path'">
                                        <td class="cur">
                                            <xsl:choose>
                                                <xsl:when test="$Main/List/params/link">
                                                    <a href="{$Root}{$Main/List/params/link}/{$id}">
                                                        <xsl:choose>
                                                            <xsl:when test="current() != ''">
                                                                <img src="{$Files}{current()}{$id}square_small{$file_name}" width="50" border="0"/>
                                                            </xsl:when>
                                                            <xsl:otherwise>
                                                                <img src="{$Images}/user50.jpg" width="50" border="0"/>
                                                            </xsl:otherwise>
                                                        </xsl:choose>
                                                    </a>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                    <a href="{$Root}/{$Controller}/{$id}">
                                                        <xsl:choose>
                                                            <xsl:when test="current() != ''">
                                                                <img src="{$Files}{current()}{$id}square_small{$file_name}" width="50" border="0"/>
                                                            </xsl:when>
                                                            <xsl:otherwise>
                                                                <img src="{$Images}/user50.jpg" width="50" border="0"/>
                                                            </xsl:otherwise>
                                                        </xsl:choose>
                                                    </a>
                                                </xsl:otherwise>
                                            </xsl:choose>
                                        </td>
                                    </xsl:when>

                                    <!-- DATE -->
                                    <xsl:when test="./row/@day">
                                        <td class="cur">
                                            <xsl:call-template name="Write.Date.Time">
                                                <xsl:with-param name="node" select="current()/row"/>
                                            </xsl:call-template>
                                        </td>
                                    </xsl:when>

                                    <!-- default LINK FIELD -->
                                    <xsl:when test="(name(.)='name' or name(.)='title' or name(.)='last_name' or name(.)='username') and not($Main/List/params/link_fields)">
                                        <td class="cur">
                                            <a href="/{$Controller}/{$id}">
                                                <xsl:value-of select="current()" disable-output-escaping="yes"/>
                                            </a>
                                        </td>
                                    </xsl:when>

                                    <xsl:otherwise>
                                        <td class="cur">
                                            <xsl:value-of select="current()" disable-output-escaping="yes"/>
                                        </td>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:for-each>

                            <!-- Function List -->
                            <xsl:for-each select="node()[@type = 'func']">
                                <td align="center">
                                    <xsl:choose>
                                        <!-- Checkbox -->
                                        <xsl:when test="./type = 'checkbox'">
                                            <a href="javascript:;" onclick="return list_func_checkbox({$id}, '{./field}');">
                                                <input type="hidden" value="{./value}" rel="{./field}{$id}"/>
                                                <div class="loader{./field}{$id}" style="display:none;">
                                                    <img src="{$Images}/loader.gif" alt="Виконується..." title="Виконується..."/>
                                                </div>
                                                <div class="func{./field}{$id}">
                                                    <xsl:choose>
                                                        <xsl:when test="./value = 1">
                                                            <div class="on" rel="{./field}{$id}" value="0">
                                                                <img src="{$Images}/{./img/on}" alt="{./alt}" title="{./alt}"/>
                                                            </div>
                                                            <div style="display:none;" class="off" rel="{./field}{$id}" value="1">
                                                                <img src="{$Images}/{./img/off}" alt="{./alt_off}" title="{./alt_off}" />
                                                            </div>
                                                        </xsl:when>
                                                        <xsl:otherwise>
                                                            <div style="display:none;" class="on" rel="{./field}{$id}" value="0">
                                                                <img src="{$Images}/{./img/on}" alt="{./alt}" title="{./alt}"/>
                                                            </div>
                                                            <div class="off" rel="{./field}{$id}" value="1">
                                                                <img src="{$Images}/{./img/off}" alt="{./alt_off}" title="{./alt_off}" />
                                                            </div>
                                                        </xsl:otherwise>
                                                    </xsl:choose>
                                                </div>
                                            </a>
                                        </xsl:when>


                                        <!-- ORDER -->
                                        <xsl:when test="./type = 'order'">
                                            <div style="width: 100px;">
                                                <xsl:choose>
                                                    <xsl:when test="$Action = 'index'">
                                                        <input type="text" name="norder" value="{./value}" rel="{$id}" size="4" old="{./value}" cat="{$Form/id_cat/row[@active=1]/id}" style="text-align: center;"/>
                                                    </xsl:when>
                                                    <xsl:otherwise>
                                                        <input type="text" name="norder" value="{./value}" rel="{$id}" size="4" old="{./value}" cat="{$Main/@id}" style="text-align: center;"/>
                                                    </xsl:otherwise>
                                                </xsl:choose>


                                                <input type="hidden" id="ajax-order-url" value="/{$Controller}/ajax-order/">
                                                    <xsl:if test="./ajax">
                                                        <xsl:attribute name="value">
                                                            <xsl:value-of select="./ajax"/>
                                                        </xsl:attribute>
                                                    </xsl:if>
                                                </input>
                                                <a style="float:left;" href="/{$Controller}/order/id/{$id}/d/1">
                                                    <xsl:if test="./url">
                                                        <xsl:attribute name="href">
                                                            <xsl:value-of select="./url"/>/id/
                                                            <xsl:value-of select="$id"/>/d/1
                                                        </xsl:attribute>
                                                    </xsl:if>
                                                    <img src="{$Images}/{./img/up}" alt="Підняти" title="Підняти"/>
                                                </a>
                                                <a style="float:left;" href="/{$Controller}/order/id/{$id}/d/2">
                                                    <xsl:if test="./url">
                                                        <xsl:attribute name="href">
                                                            <xsl:value-of select="./url"/>/id/
                                                            <xsl:value-of select="$id"/>/d/2
                                                        </xsl:attribute>
                                                    </xsl:if>
                                                    <img src="{$Images}/{./img/down}" alt="Опустити" title="Опустити" />
                                                </a>

                                            </div>
                                        </xsl:when>

                                        <!-- Button -->
                                        <xsl:when test="./type = 'button'">
                                            <div class="loader{./field}{$id}" style="display:none;">
                                                <img src="{$Images}/loader.gif" alt="Виконується..." title="Виконується..."/>
                                            </div>
                                            <div class="func{./field}{$id}">
                                                <a href="javascript:;" onclick="{./url}">
                                                    <img src="{$Images}/icons/{./img}" alt="{./alt}" title="{./alt}"/>
                                                </a>
                                            </div>
                                        </xsl:when>
                                    </xsl:choose>
                                </td>
                            </xsl:for-each>
                        </tr>
                    </xsl:for-each>
                </tbody>

            </table>

            <xsl:if test="$Main/List/data/pager/end_page > 1">
                <div class="pages">
                    <xsl:call-template name="pager1">
                        <xsl:with-param name="node" select="/page/content/Main/List/data/pager"></xsl:with-param>
                    </xsl:call-template>
                    <input name="pager_submit" type="submit" value="Показувати:" />
                    <select name="pager_count" >
                        <xsl:for-each select="$Main/List/pager_count_list/row">
                            <option value="{current()}">
                                <xsl:if test="$Main/List/pager_count_list/@active = current()">
                                    <xsl:attribute name="selected">
                                        selected
                                    </xsl:attribute>
                                </xsl:if>
                                <xsl:value-of select="current()"/>
                            </option>
                        </xsl:for-each>
                    </select>

                </div>
            </xsl:if>
        </form>
    </xsl:template>

    <xsl:template name="pager1">
        <xsl:param name="node"></xsl:param>

        <xsl:variable name="sort" select="/page/content/main/@sort" />
        <xsl:variable name="family" select="/page/content/main/@family" />
        <xsl:variable name="fromTopic" select="/page/content/main/@fromTopic" />

        <!-- page left -->
        <div class="fclr"></div>

        <xsl:if test="number($node/page_count) &gt; 1">

            <div class="ArtPager">
                <span class="innerText">
                    Показано с
                    <xsl:value-of select="number($node/start_item)" />
                    по
                    <xsl:value-of select="$node/end_item" />
                    из
                    <xsl:value-of select="$node/items_count" />

                </span>

                <div class="pageLeft"></div>
                <a href="#" class="pageCenter">
                    <xsl:choose>
                        <xsl:when test="number($node/current_page) &gt; 1">
                            <xsl:attribute name="href">
                                <xsl:text>?page=</xsl:text>
                                <xsl:value-of select="number($node/current_page) - 1"/>

                                <xsl:if test="string-length($sort) &gt; 0">
                                    <xsl:text>&amp;sort=</xsl:text>
                                    <xsl:value-of select="$sort"/>
                                </xsl:if>

                                <xsl:if test="string-length($family) &gt; 0">
                                    <xsl:text>&amp;family=</xsl:text>
                                    <xsl:value-of select="$family"/>
                                </xsl:if>

                                <xsl:if test="string-length($fromTopic) &gt; 0">
                                    <xsl:text>&amp;fromTopic=</xsl:text>
                                    <xsl:value-of select="$fromTopic"/>
                                </xsl:if>


                            </xsl:attribute>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:attribute name="style">
                                cursor:default;
                            </xsl:attribute>
                        </xsl:otherwise>
                    </xsl:choose>
                    <xsl:text> </xsl:text>
                    <img src="{$Images}/pagerleft.gif" alt="" border="0" style="position:relative; top:4px;" />
                </a>
                <div class="pageRight"></div>



                <xsl:call-template name="pager1.counter">
                    <xsl:with-param name="i" select="$node/start_page"></xsl:with-param>
                    <xsl:with-param name="node" select="$node"></xsl:with-param>
                </xsl:call-template>


                <span class="innerText2"> із </span>

                <div class="pageLeft"></div>
                <a href="?page={$node/last_page}" class="pageCenter">

                    <xsl:if test="string-length($sort) &gt; 0">
                        <xsl:attribute name="href">
                            <xsl:text>?page=</xsl:text>
                            <xsl:value-of select="$node/last_page"/>
                            <xsl:text>&amp;sort=</xsl:text>
                            <xsl:value-of select="$sort"/>
                        </xsl:attribute>
                    </xsl:if>

                    <xsl:if test="string-length($family) &gt; 0">
                        <xsl:attribute name="href">
                            <xsl:text>?page=</xsl:text>
                            <xsl:value-of select="$node/last_page"/>
                            <xsl:text>&amp;family=</xsl:text>
                            <xsl:value-of select="$family"/>
                        </xsl:attribute>
                    </xsl:if>

                    <xsl:if test="string-length($fromTopic) &gt; 0">
                        <xsl:attribute name="href">
                            <xsl:text>?page=</xsl:text>
                            <xsl:value-of select="$node/last_page"/>
                            <xsl:text>&amp;fromTopic=</xsl:text>
                            <xsl:value-of select="$fromTopic"/>
                        </xsl:attribute>
                    </xsl:if>

                    <xsl:value-of select="$node/last_page"/>
                </a>
                <div class="pageRight"></div>

                <div class="pageLeft"></div>
                <a href="#" class="pageCenter">
                    <xsl:choose>
                        <xsl:when test="number($node/current_page) &lt; number($node/last_page)">
                            <xsl:attribute name="href">
                                <xsl:text>?page=</xsl:text>
                                <xsl:value-of select="number($node/current_page) + 1"/>


                                <xsl:if test="string-length($sort) &gt; 0">
                                    <xsl:text>&amp;sort=</xsl:text>
                                    <xsl:value-of select="$sort"/>
                                </xsl:if>

                                <xsl:if test="string-length($family) &gt; 0">
                                    <xsl:text>&amp;family=</xsl:text>
                                    <xsl:value-of select="$family"/>
                                </xsl:if>

                                <xsl:if test="string-length($fromTopic) &gt; 0">
                                    <xsl:text>&amp;fromTopic=</xsl:text>
                                    <xsl:value-of select="$fromTopic"/>
                                </xsl:if>

                            </xsl:attribute>
                        </xsl:when>
                    </xsl:choose>
                    <img src="{$Images}/pagerright.gif" alt="" border="0" style="position:relative; top:4px;"/>
                    <xsl:text> </xsl:text>
                </a>
                <div class="pageRight"></div>

                <div class="fclr"></div>
            </div>
            <!-- pager right -->
        </xsl:if>
    </xsl:template>

    <xsl:template name="pager1.counter">
        <xsl:param name="i"></xsl:param>
        <xsl:param name="node"></xsl:param>

        <xsl:variable name="sort" select="/page/content/main/@sort" />
        <xsl:variable name="family" select="/page/content/main/@family" />
        <xsl:variable name="fromTopic" select="/page/content/main/@fromTopic" />

        <xsl:choose>
            <xsl:when test="number($node/current_page) = number($i)">
                <div class="pageLeftActive"></div>
                <a  href="#" class="pageCenterActive" style="cursor:default;">
                    <xsl:value-of select="$i"/>
                </a>
                <div class="pageRightActive"></div>
            </xsl:when>
            <xsl:otherwise>
                <!-- show -> -->
                <div class="pageLeft"></div>
                <a href="?page={$i}" class="pageCenter">

                    <xsl:if test="string-length($sort) &gt; 0">
                        <xsl:attribute name="href">
                            <xsl:text>?page=</xsl:text>
                            <xsl:value-of select="$i"/>
                            <xsl:text>&amp;sort=</xsl:text>
                            <xsl:value-of select="$sort"/>
                        </xsl:attribute>
                    </xsl:if>

                    <xsl:if test="(string-length($family) &gt; 0) or (string-length($fromTopic) &gt; 0)">
                        <xsl:attribute name="href">
                            <xsl:text>?page=</xsl:text>
                            <xsl:value-of select="$i"/>
                            <xsl:text>&amp;family=</xsl:text>
                            <xsl:value-of select="$family"/>
                            <xsl:text>&amp;fromTopic=</xsl:text>
                            <xsl:value-of select="$fromTopic"/>
                        </xsl:attribute>
                    </xsl:if>
                    <xsl:value-of select="$i"/>
                </a>
                <div class="pageRight"></div>
            </xsl:otherwise>
        </xsl:choose>

        <!-- test -> -->
        <xsl:if test="(number($i) &lt; (number($node/start_page)+4)) and number($i) &lt; (number($node/last_page)) ">
            <xsl:call-template name="pager1.counter">
                <xsl:with-param name="i" select="$i+1"></xsl:with-param>
                <xsl:with-param name="node" select="$node"></xsl:with-param>
            </xsl:call-template>
        </xsl:if>

    </xsl:template>

</xsl:stylesheet>